package cn.stylefeng.guns.modular.goodsCart.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.goodsCart.entity.TaoGoodCart;
import cn.stylefeng.guns.modular.goodsCart.mapper.TaoGoodCartMapper;
import cn.stylefeng.guns.modular.goodsCart.model.params.TaoGoodCartParam;
import cn.stylefeng.guns.modular.goodsCart.model.result.TaoGoodCartResult;
import  cn.stylefeng.guns.modular.goodsCart.service.TaoGoodCartService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 购物车 服务实现类
 * </p>
 *
 * @author lcw
 * @since 2019-09-25
 */
@Service
public class TaoGoodCartServiceImpl extends ServiceImpl<TaoGoodCartMapper, TaoGoodCart> implements TaoGoodCartService {
    @Resource
    TaoGoodCartMapper taoGoodCartMapper;

    @Override
    public void add(TaoGoodCartParam param){
        TaoGoodCart entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(TaoGoodCartParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void deleteBygoodId(String goodId,String openId){
        taoGoodCartMapper.deleteBygoodId(goodId,openId);
    }

    @Override
    public void deleteByType(TaoGoodCartParam param) {
        taoGoodCartMapper.deleteByType(param);
    }


    @Override
    public void update(TaoGoodCartParam param){
        TaoGoodCart oldEntity = getOldEntity(param);
        TaoGoodCart newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public TaoGoodCartResult findBySpec(TaoGoodCartParam param){
        return null;
    }

    @Override
    public List<TaoGoodCartResult> findListBySpec(TaoGoodCartParam param){
        return null;
    }

    @Override
    public LayuiPageInfo findPageBySpec(TaoGoodCartParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    @Override
    public List<Map<String, Object>> getgoodCartbyphone(String phone) {
        return taoGoodCartMapper.getgoodCartbyphone(phone);
    }

    private Serializable getKey(TaoGoodCartParam param){
        return null;
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private TaoGoodCart getOldEntity(TaoGoodCartParam param) {
        return this.getById(getKey(param));
    }

    private TaoGoodCart getEntity(TaoGoodCartParam param) {
        TaoGoodCart entity = new TaoGoodCart();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
